/*
 * @Author: szx
 * @Date: 2022-04-19 17:10:05
 * @LastEditTime: 2022-04-19 17:29:17
 * @Description:
 * @FilePath: \leetcode\800-899\819\819.js
 */
/**
 * @param {string} paragraph
 * @param {string[]} banned
 * @return {string}
 */
var mostCommonWord = function (paragraph, banned) {
    const set = new Set(banned);
    const map = new Map();
    paragraph = paragraph.toLowerCase().replace(/[!?',;.]/g, ' ');
    const words = paragraph.split(' ').filter((word) => word && !set.has(word));
    let res = 0;
    let max = 0;
    for (let w of words) {
        const val = (map.get(w) || 0) + 1;
        map.set(w, val);
        if (val > max) {
            max = val;
            res = w;
        }
    }
    return res;
};
